package com.cloud.cloudvideo.controller;

import java.io.IOException;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cloud.cloudvideo.entity.Plupload;
import com.cloud.cloudvideo.entity.ResultModel;
import com.cloud.cloudvideo.entity.VideoCatePo;
import com.cloud.cloudvideo.entity.VideoMedia;
import com.cloud.cloudvideo.entity.VideoMediaPo;
import com.cloud.cloudvideo.service.VideoMediaService;

@Controller
@RequestMapping("/video")
public class VideoController {

	@Autowired
	private VideoMediaService videoService;

	@RequestMapping("/tolist")
	public String tovideolist() {
		return "manager/video/video_list";
	}

	@RequestMapping("/list")
	@ResponseBody
	public ResultModel<List<VideoMediaPo>> list(String mediaorginalname) {
		List<VideoMediaPo> list = videoService.list(mediaorginalname);
		return ResultModel.successWithData(list, list.size());
	}

	@RequestMapping("/toAdd")
	public String toAdd() {
		return "manager/video/video_add";
	}
	
	
	@RequestMapping("/toModify")
	public String toModify(Long id,Model model) {
		VideoMediaPo vcp = videoService.videoInfo(id);
		model.addAttribute("videomediapo", vcp);
		return "manager/video/video_edit";
	}
	
	
	/**
	 * 查看视频信息
	 * @param id
	 * @param model
	 * @return
	 */
	@RequestMapping("/toVdeoInfo")
	public String toVdeoInfo(Long id,Model model) {
		VideoMediaPo vcp = videoService.videoInfo(id);
		model.addAttribute("videomediapo", vcp);
		return "manager/video/video_info";
	}
	
	
	
	@RequestMapping("/add")
	@ResponseBody
	public ResultModel add(VideoMedia vm ) {
		videoService.modifyVideoMedia(vm);
		return ResultModel.successWithNoData();
	}

	@RequestMapping("/upload")
	@ResponseBody
	// @RequiresPermissions("system:video:view")
	public ResultModel upload(Plupload upload, String key, HttpServletRequest request) throws IOException {
		upload.setRequest(request);
		videoService.uploadFile(upload,key);
		return ResultModel.successWithData(key, 1);
	}
	
	
	@RequestMapping("/del")
	@ResponseBody
	public ResultModel del(Long id ) {
		videoService.del(id);
		return ResultModel.successWithNoData();
	}
	

	
	
	
	
}
